package com.example.figurehecheng.controller.merchant;


import com.example.figurehecheng.common.result.Result;
import com.example.figurehecheng.domain.dto.HumanityDTO;
import com.example.figurehecheng.domain.vo.HumanityVO;
import com.example.figurehecheng.service.IHumanityService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 人文关系表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-18
 */
@RestController("adminHumanityController")
@RequestMapping("/admin/humanity")
@CrossOrigin
@RequiredArgsConstructor
public class HumanityController {
    @Autowired
    private IHumanityService humanityService;

    /**
     * 创建人文
     * @param dto
     * @return
     */
    @RequestMapping("/create")
    @ApiOperation("创建人文")
    public Result<Long> createHumanity(@RequestBody @Valid HumanityDTO dto){
        long id = humanityService.createHumanity(dto);
        return Result.success(id);
    }
    /**
     * 获取人文列表
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取人文列表")
    public Result<List<HumanityVO>> getHumanityList(){
        List<HumanityVO> list = humanityService.getHumanityList();
        return Result.success(list);
    }

    /**
     * 获取人文详情
     * @param
     * @return
     */
    @RequestMapping("/detail/{id}")
    @ApiOperation("获取人文详情")
    public Result<HumanityVO> getHumanityDetail(@PathVariable Long id){
        HumanityVO humanityVO = humanityService.getHumanityDetail(id);
        return Result.success(humanityVO);
    }

    /**
     * 修改人文信息
     * @param
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改人文信息")
    public Result<Boolean> updateHumanity(@RequestBody @Valid HumanityDTO dto){
        boolean update = humanityService.updateHumanity(dto);
        return Result.success(update);
    }

    /**
     * 删除人文信息
     * @param
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除人文信息")
    public Result<Boolean> deleteHumanity(@PathVariable Long id){
        boolean delete = humanityService.removeById(id);
        return Result.success(delete);
    }
}
